home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-12-24 | 6.2 KB | 309 lines | [TEXT/PJMM] |
- unit MatrixOperations;
-
- interface
-
- uses
- Globals;
-
-
-
- procedure matrixoperations (var amat, bmat, cmat: hdlsinglearraymatrix; var m1, n1, m2, n2, m3, n3: longint; var matrixoper: string30; var error: str255; var realresult: extended);
-
-
- implementation
-
-
- procedure matrixoperations;
-
- label
- 999;
-
- var
- i, j, k, l, ktype, numberofcols, aa, bb, mvalue: longint;
- a, b, c, sum, x: extended;
- bstring: str255;
- realbinoperator: stringsize;
-
-
-
-
- procedure realbinaryoperations1 (var realbinoperator: stringsize; var b1, b2, b3: extended; var error: str255);
-
- label
- 999;
-
- begin
-
- if realbinoperator = plus then
- b3 := b1 + b2;
- if realbinoperator = minus then
- b3 := b1 - b2;
- if realbinoperator = asterisk then
- b3 := b1 * b2;
- if realbinoperator = crosshatch then
- b3 := b1 * b2;
- if realbinoperator = equals then
- b3 := b2;
- if (realbinoperator = leftslash) and (b1 <> 0) then
- b3 := b2 / b1;
- if (realbinoperator = leftslash) and (b1 = 0) then
- writeln('divide by zero');
- if (realbinoperator = rightslash) and (b2 <> 0) then
- b3 := b1 / b2;
- if (realbinoperator = rightslash) and (b2 = 0) then
- writeln('divide by zero');
- if realbinoperator = exponent then
- begin
- if b1 = 0 then
- b3 := 0;
- if (b1 < 0) then
- b3 := -exp(b2 * ln(-b1));
- if b1 > 0 then
- b3 := exp(b2 * ln(b1));
- if b2 = 0 then
- b3 := 1;
- end;
-
-
- 999:
- end;
-
-
- begin
-
-
- if (matrixoper = asterisk) then
- begin
- m3 := m1;
- n3 := n2;
-
- for i := 1 to m1 * n1 do
- amat^^[i] := amat^^[i + 2];
-
- for i := 1 to m2 * n2 do
- bmat^^[i] := bmat^^[i + 2];
-
- cmat^^[1] := m3;
- cmat^^[2] := n3;
-
- l := 0;
- for i := 1 to m1 do
- for j := 1 to n2 do
- begin
- l := l + 1;
- sum := 0;
- for k := 1 to n1 do
- sum := sum + amat^^[(i - 1) * n1 + k] * bmat^^[(k - 1) * n2 + j];
- cmat^^[l + 2] := sum;
- end;
- realresult := cmat^^[3];
-
- goto 999;
- end;
-
- if (matrixoper <> asterisk) then
- begin
-
- realbinoperator := matrixoper;
- if (m1 = 1) and (n1 = 1) then
- begin
- m3 := m2;
- n3 := n2;
- cmat^^[1] := m2;
- cmat^^[2] := n2;
- i := 3;
- repeat
- a := amat^^[3];
- b := bmat^^[i];
- realbinaryoperations1(realbinoperator, a, b, c, error);
- cmat^^[i] := c;
- i := i + 1;
- until i > m2 * n2 + 2;
- goto 999;
- end;
-
- if (m2 = 1) and (n2 = 1) then
- begin
- m3 := m1;
- n3 := n1;
- cmat^^[1] := m1;
- cmat^^[2] := n1;
- i := 3;
- repeat
- a := amat^^[i];
- b := bmat^^[3];
- realbinaryoperations1(realbinoperator, a, b, c, error);
- cmat^^[i] := c;
- i := i + 1;
- until i > m1 * n1 + 2;
- goto 999;
- end;
-
- if (m1 > 1) and (n1 > 1) and (m2 > 1) and (n2 > 1) then
- begin
- m3 := m2;
- n3 := n2;
- cmat^^[1] := m2;
- cmat^^[2] := n2;
-
- i := 3;
- repeat
- a := amat^^[i];
- b := bmat^^[i];
- realbinoperator := matrixoper;
- realbinaryoperations1(realbinoperator, a, b, c, error);
- cmat^^[i] := c;
- if (i = 1) then
- realresult := c;
- i := i + 1;
- until i > m1 * n1 + 2;
-
- end;
-
-
- if (m1 = 1) and (n1 > 1) and (m2 > 1) and (n2 > 1) then
- begin
- m3 := m2;
- n3 := n2;
-
- cmat^^[1] := m3;
- cmat^^[2] := n3;
-
- l := 0;
- for i := 1 to m3 do
- for j := 1 to n3 do
- begin
- l := l + 1;
- a := amat^^[j + 2];
- b := bmat^^[n3 * (i - 1) + j + 2];
- realbinoperator := matrixoper;
- realbinaryoperations1(realbinoperator, a, b, c, error);
- cmat^^[l + 2] := c;
- if (l + 2 = 3) then
- realresult := c;
- end;
- end;
-
-
- if (m1 = 1) and (m2 = 1) and (n1 > 1) and (n2 > 1) then
- begin
- m3 := 1;
- n3 := n2;
-
- cmat^^[1] := m3;
- cmat^^[2] := n3;
-
- for i := 3 to m3 * n3 + 2 do
- begin
- a := amat^^[i];
- b := bmat^^[i];
- realbinoperator := matrixoper;
- realbinaryoperations1(realbinoperator, a, b, c, error);
- cmat^^[i] := c;
- if i = 3 then
- realresult := c;
- end;
-
- end;
-
-
- if (m2 = 1) and (m1 > 1) and (n1 > 1) and (n2 > 1) then
- begin
- m3 := m1;
- n3 := n2;
-
- cmat^^[1] := m3;
- cmat^^[2] := n3;
-
- l := 0;
- for i := 1 to m3 do
- for j := 1 to n3 do
- begin
- l := l + 1;
- a := amat^^[n3 * (i - 1) + j + 2];
- b := bmat^^[j + 2];
- realbinoperator := matrixoper;
- realbinaryoperations1(realbinoperator, a, b, c, error);
- cmat^^[l + 2] := c;
- if (l + 2 = 3) then
- realresult := c;
- end;
-
- end;
-
- if (n1 = 1) and (m1 > 1) and (m2 > 1) and (n2 > 1) then
- begin
- m3 := m2;
- n3 := n2;
-
- cmat^^[1] := m3;
- cmat^^[2] := n3;
-
- l := 0;
- for i := 1 to m3 do
- for j := 1 to n3 do
- begin
- l := l + 1;
- a := amat^^[(i - 1) + 3];
- b := bmat^^[n3 * (i - 1) + j + 2];
- realbinoperator := matrixoper;
- realbinaryoperations1(realbinoperator, a, b, c, error);
- cmat^^[l + 2] := c;
- if (l = 1) then
- realresult := c;
- end;
-
- end;
-
-
- if (n1 = 1) and (n2 = 1) and (m1 > 1) and (m2 > 1) then
- begin
- m3 := m2;
- n3 := 1;
-
- cmat^^[1] := m3;
- cmat^^[2] := n3;
-
- for i := 3 to m3 * n3 + 2 do
- begin
- a := amat^^[i];
- b := bmat^^[i];
- realbinoperator := matrixoper;
- realbinaryoperations1(realbinoperator, a, b, c, error);
- cmat^^[i] := c;
- if i = 3 then
- realresult := c;
- end;
-
- end;
-
- if (n2 = 1) and (m2 > 1) and (n1 > 1) and (m1 > 1) then
- begin
- m3 := m2;
- n3 := n1;
-
- cmat^^[1] := m3;
- cmat^^[2] := n3;
-
- l := 0;
- for i := 1 to m3 do
- for j := 1 to n3 do
- begin
- l := l + 1;
- a := amat^^[n3 * (i - 1) + j + 2];
- b := bmat^^[(i - 1) + 3];
- realbinoperator := matrixoper;
- realbinaryoperations1(realbinoperator, a, b, c, error);
- cmat^^[l + 2] := c;
- if (l = 1) then
- realresult := c;
- end;
- end;
-
- end;
-
-
- 999:
- end;
-
- end.